package com.monkey.core.plugin.service;

import com.monkey.core.domain.BaseEntity;
import com.monkey.core.plugin.domain.Treeable;
import com.monkey.core.repository.search.Searchable;
import com.monkey.core.service.BaseService;

import java.io.Serializable;
import java.util.List;
import java.util.Set;


public interface BaseTreeableService<M extends BaseEntity<ID> & Treeable<ID, M>, ID extends Serializable> extends BaseService<M, ID> {


    public void deleteSelfAndChild(M m);

    public void deleteSelfAndChild(List<M> mList);

    public void appendChild(M parent, M child);

    public int nextWeight(ID id);


    /**
     * 移动节点
     * 根节点不能移动
     *
     * @param source   源节点
     * @param target   目标节点
     * @param moveType 位置
     */
    public void move(M source, M target, String moveType);


    /**
     * 把源节点全部变更为目标节点
     *
     * @param source
     * @param newParentIds
     */
    public void updateSelfAndChild(M source, ID newParentId, String newParentIds, int newWeight);

    /**
     * 查找目标节点及之后的兄弟  注意：值与越小 越排在前边
     *
     * @param parentIds
     * @param currentWeight
     * @return
     */
    public List<M> findSelfAndNextSiblings(String parentIds, int currentWeight);


    /**
     * 查看与name模糊匹配的名称
     *
     * @param name
     * @return
     */
    public Set<String> findNames(Searchable searchable, String name, ID excludeId);


    /**
     * 查询节点下的所有子节点
     *
     * @return
     */
    public M findChildren(ID parentId, boolean containDisable);

    public List<M> findAllByName(Searchable searchable, M excludeM);

    /**
     * 查找根和一级节点
     *
     * @param searchable
     * @return
     */
    public List<M> findRootAndChild(Searchable searchable);

    public List<M> findChildByParent(ID parentId, boolean containDisable);

    /**
     * 查询出根节点和所有的children
     *
     * @return
     */
//    public <T extends ExtTreeJSONDto<M, ID>> T findAllToExtTreeJSONDto(Class<T> clazz, ID parentId);

    /**
     * 查询指定父节点的child
     */
//    public <T extends ExtTreeJSONDto<M, ID>> List<T> findChildToExtJSONDtoByParent(Class<T> clazz, ID parentId);
    public List<ID> findChildrenIds(M parent);

    public Set<ID> findAncestorIds(Iterable<ID> currentIds);

    public Set<ID> findAncestorIds(ID currentId);

    /**
     * 递归查询祖先
     *
     * @param parentIds
     * @return
     */
    public List<M> findAncestor(String parentIds);


    public void addExcludeSearchFilter(Searchable searchable, M excludeM);


}
